sha1 = require('../utils/sha1.js');

getNoncestr=->
    return Math.random().toString(36).substr(2); # 生成随机字符串

getTimeStamp=->
    return parseInt(Date.now().toString().substring(0, 10))

getUrl=(req)->
    return "http://www.wpax.cn" + req.originalUrl

token = "wpax"


# 验证第三方开发者
exports.checkSignature = ->
    echostr = this.query.echostr;
    signature = this.query.signature;
    timestamp = this.query.timestamp;
    nonce = this.query.nonce;

    tmpArr = [token, timestamp, nonce]
    tmpStr = tmpArr.sort().join("")

    shaStr = sha1(tmpStr)
    console.log('signature:' + signature);
    if shaStr == signature
        console.log("success echostr:" + echostr)
        this.send(echostr);
    else
        console.log("error:" + echostr)
        this.send("error test");

